﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		StringExtensionsForSystemIO.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            StringExtensionsForSystemIO.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 
namespace System.IO {
	///<summary>
	///	Extends the System classes
	///</summary>
	///<remarks>
	///	All methods included in this class should be used into <see cref = "System.IO" /> context.
	///</remarks>
	public static class StringExtensionsForSystemIO {
		/// <summary>
		/// 	This method remove invalid chars from the file name, and truncate the name if it will be greater then 250 chars.
		/// </summary>
		/// <param name = "filename">The filename.</param>
		/// <returns>The cleaned filename</returns>
		///<exception cref="ArgumentNullException"> If <paramref name="filename"/> is <c>null</c>.</exception>
		///<exception cref="ArgumentOutOfRangeException"> If <paramref name="filename"/> is <c>empty</c>.</exception>
		public static string CleanFileName ( this string filename ) {
			if(filename == null)
				throw new ArgumentNullException("fileName");
			
			if (filename == "")
				throw new ArgumentException ( );
				
			string file = filename;
			file = string.Concat ( file.Split ( Path.GetInvalidFileNameChars ( ) , StringSplitOptions.RemoveEmptyEntries ) );

			if ( file.Length > 250 ) {
				file = file.Substring ( 0 , 250 );
			}
			return file;
		}
	}
}
